/**
 * @Author MrsGuo
 * version 1.0
 * @Date 2023-08-11 15:44
 */
package com.cl.erp_2301.Service.impl;

import com.cl.erp_2301.Service.StartService;
import com.cl.erp_2301.dto.MarketDTO;

import com.cl.erp_2301.dto.StoreOperDTO;
import com.cl.erp_2301.mapper.StartMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class StartServiceImpl implements StartService {
    @Resource
    private StartMapper startMapper;

    @Override
    public void doStartMarket(Integer uuid,String startername) {
        String ender=startMapper.selectEnder(uuid);
      Date date=new Date();
        MarketDTO marketDTO=new MarketDTO();
        marketDTO.setStarttime(date);
        marketDTO.setStartername(startername);
        marketDTO.setUuid(uuid);
        marketDTO.setEndername(ender);
        marketDTO.setEndtime(date);
        startMapper.doStartMarket(marketDTO);
        startMapper.doStartMarketDetail(marketDTO);
    }

    @Override
    public void insertStoreOp(StoreOperDTO storeOpDTO) {
        Date date=new Date();
        storeOpDTO.setOpertime(date);
       startMapper.insertStoreOp(storeOpDTO);

    }

    @Override
    public void updateStoreNum(MarketDTO marketDTO) {
        Integer marketNum=marketDTO.getNum();
        Integer storeNum=startMapper.selectStoreDetailNum(marketDTO.getGoodsuuid());
        Integer num=marketNum+storeNum;
        Integer goodsuuid=marketDTO.getGoodsuuid();
        startMapper.updateStoreNum(num,goodsuuid);
    }

    @Override
    public StoreOperDTO selectStoreOp(Integer uuid) {
        return startMapper.selectStoreOp(uuid);
    }

    @Override
    public MarketDTO selectGooduuid(Integer uuid) {
        return startMapper.selectGooduuid(uuid);
    }

    @Override
    public Integer selectStoreDetailNum(Integer goodsuuid) {
        return startMapper.selectStoreDetailNum(goodsuuid);
    }
}
